<template>
  <div>
    <!-- 请假 最近申请-->
    <AppliCard
      :tableData="appliData"
      @handlerApproval="teacherApproval"
    />
    <!-- 请假 最近审核 -->
    <AduitCard
      :tableData="aduitData"
    />
    <!-- 驳回 批准 -->
    <DialogComp
    @submit= "handlerSubmit"
    :show="showDialog"/>
  </div>
</template>
<script>
import AppliCard from './child/AppliCard'
import AduitCard from './child/AduitCard'
import { Toast } from 'vant'
export default {
  data() {
    return {
      appliData: [],
      aduitData: [],
      apparParams: '', // 审批参数
      showDialog: {
        open: false,
      },
    }
  },
  components: {
    AppliCard,
    AduitCard,
  },
  created() {
    this.getLeaveList()
  },
  methods: {
    getLeaveList() {
      this.$api.leave.getLeaveList({}).then(res=> {
        this.reastTable()
        res.data.data.forEach(element => {
          /* 1未审批 其他已审批 */
          if (element.status === 1) this.appliData.push(element)
          else this.aduitData.push(element)
        })
      })
    },
    teacherApproval(value) {
      /* 批准 驳回 弹窗 */
      this.apparParams = value
      this.showDialog = { open: true }
    },
    reastTable() {
      this.appliData =[]
      this.aduitData= []
    },
    handlerSubmit(desc) {
      /* 审批提交 */
      this.apparParams.reject_desc = desc
      this.$api.leave.approLeave(this.apparParams).then(res=> {
        if (res.status === 200) {
          Toast.success('审批成功')
          this.getLeaveList()
        } else {
          Toast.fail(res.msg)
        }
      })
    },
  },
}
</script>